<template>
  <basic-container>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <avue-crud
        :data="scheduleData"
        :option="option"
        :page="page"
        :table-loading="tableLoading"
        @size-change="sizeChange"
        @current-change="currentChange"
        @search-change="searchChange"
        @search-reset="searchReset"
        class="avuecrud"
      >
        <template slot="menuRight">
          <el-button type="warning" size="small" @click="exportToDoReportData()">导出</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <div class="menu-title" @click.stop="reportValidate(scope.row,scope.index)">
            <i class="iconfont iconview icon-primary"></i>
            <p class="menu-title-text">办理</p>
          </div>
          <div class="menu-title" @click.stop="assign(scope.row,scope.index)">
            <i class="iconfont iconalter icon-warning"></i>
            <p class="menu-title-text">转办</p>
          </div>
        </template>
      </avue-crud>
      <el-dialog title="流程图" :visible.sync="showPicDialog" width="1200px">
        <img :src="actPicUrl" width="100%" />
      </el-dialog>
      <assign :visible="assignVisible" :task-id="taskIdAssign" @cancelAssign="cancelAssign"></assign>
    </div>
  </basic-container>
</template>
<script>
import { toDoReportList,exportToDoReportDataExcel } from '@/api/pim/pim'
import { REVIEW_DIC, PROJECT_DIC } from '@/const/dict'

export default {
  name: 'todoReport',
  data() {
    return {
      headerData: {
        title: '监测评估'
      },
      actPicUrl: '',
      showPicDialog: false,
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 10 // 每页显示多少条
      },
      tableLoading: false,
      scheduleData: [],
      option: {
        page: true,
        addBtn: false,
        editBtn: false,
        addRowBtn: false,
        indexLabel: '序号',
        index: true,
        cellBtn: false,
        delBtn: false,
          indexWidth:70,
        columnBtn: false,
        refreshBtn: false,
        filterBtn: false,
        searchBtn: false,
        menuWidth: 150,
        keyId: 'id',
        column: [
          {
            label: '规划名称',
            prop: 'title',
            search: true,
            cell: true
          },
          {
            label: '报告类型',
            prop: 'reportType',
            width: '120',
            dicData: [
              {
                label: '年度监测分析报告',
                value: '1'
              },
              {
                label: '中期评估报告',
                value: '2'
              },
              {
                label: '期末总结报告',
                value: '3'
              }
            ],
            cell: true
          },
          {
            label: '起草单位',
            prop: 'createUnit',
            width: '140',
            cell: true
          },
          {
            label: '环节',
            prop: 'taskName',
            type: 'select',
            width: '100',
            cell: true
          }
        ]
      },
      assignVisible: false,
      taskIdAssign: null,
      titleLikeSearch:''
    }
  },
  created() {
    this.getToDoList(this.page)
  },
  methods: {
    getToDoList(page, params) {
      this.tableLoading = true;
      toDoReportList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize
          },
          params
        )
      ).then(response => {
        this.scheduleData = response.data.data.records;
        this.page.total = response.data.data.total;
        this.tableLoading = false;
        this.$emit('getTotal', response.data.data.total)
      })
    },
    searchReset() {
      this.titleLikeSearch = '';
      let params = {
        titleLike:this.titleLikeSearch,
      };
      this.getToDoList(this.page,params)
    },
    //搜索回调
    searchChange(params) {
      this.page.currentPage = 1
      this.getToDoList(this.page, this.dealSearchParam(params))
    },
    // 处理搜索过滤
    dealSearchParam(params) {
      if (params.title) {
        params.titleLike = params.title;
      }
      this.titleLikeSearch = params.title;
      return params
    },
    currentChange(currentPage) {
      var page = this.page;
      page.currentPage = currentPage;
      let params = {
        titleLike:this.titleLikeSearch,
      };
      this.getToDoList(page,params);
    },
    sizeChange(pageSize) {
      var page = this.page;
      page.pageSize = pageSize;
      let params = {
        titleLike:this.titleLikeSearch,
      };
      this.getToDoList(page,params);
    },
    // 办理
    reportValidate(row, index) {
      if (row.reportState == '3') {
        let src = `/reportValidate/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            considerOpinion: row.considerOpinion
          }
        })
      } else if (row.reportState == '7') {
        let src = `/reportValidate/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            considerOpinion: row.considerOpinion
          }
        })
      } else if (row.reportState == '10') {
        let src = `/reportValidate/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            considerOpinion: row.considerOpinion
          }
        })
      } else if (row.reportState == '9') {
        let src = `/reportTwoValidate/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            opinion: row.opinion
          }
        })
      } else if (row.reportState == '11') {
        let src = `/reportReview/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            opinion: row.opinion
          }
        })
      } else if (row.reportState == '5' && row.havModifyOpinion) {
        let src = `/reportExamine/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            opinion: row.opinion
          }
        })
      } else if (row.reportState == '5' && !row.havModifyOpinion) {
        let src = `/reportReview/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            opinion: row.opinion
          }
        })
      } else if (row.reportState == '4') {
        let src = `/reportEdit/detail/${row.taskId}`;
        this.$router.push({
          path: src,
          query: {
            reportId: row.reportId,
            opinion: row.opinion,
            considerOpinion: row.considerOpinion,
            reportState: row.reportState
          }
        })
      }
    },
    handleSubmit() {},
    // 详情
    viewDetail(row, index) {
      let src = `/reviewDetail/detail/${row.reviewId}`;
      this.$router.push({
        path: src
      })
    },
    // 流程图
    flowChart(row, index) {
      this.actPicUrl = `/planning/registerinfo/task/view/` + row.taskId;
      this.showPicDialog = true
    },
    assign(row) {
      this.taskIdAssign = row.taskId;
      this.assignVisible = true;
    },
    cancelAssign() {
      this.assignVisible = false;
    },
    exportToDoReportData(){
      this.$confirm("确定要导出监测评估列表吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        exportToDoReportDataExcel().then(response => {
          let exportFileName = "监测评估列表.xlsx";
          this.download(response.data, exportFileName)
        });
      })
    },
    // 下载文件
    download(data, filename) {
      if (data == null) {

      } else {
        let url = window.URL.createObjectURL(new Blob([data]));
        let link = document.createElement('a');
        link.style.display = 'none';
        link.href = url;
        link.setAttribute('download', filename);
        document.body.appendChild(link);
        link.click()
      }
    },
  }
}
</script>

<style lang="scss" scoped>
</style>
